package day9;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;
/**
 * @author oldliu
 * @since 1.0
 */
public class MyServer {
    public static void main(String[] args) {
        try {
            ServerSocket st=new ServerSocket(9999);
            System.out.println("listen on 9999端口");
            while (true){
                Socket s = st.accept();
                System.out.println(s+"链接了。。。");
                System.out.println(s.getInetAddress());
                System.out.println(s.getPort());
                System.out.println(s.getLocalPort());
                InputStream in = s.getInputStream();
                OutputStream out = s.getOutputStream();
                int ch=0;
                while((ch=in.read())!=-1){
                    System.out.print((char)ch);
                }
                out.write("Your message,We get it".getBytes());
                out.flush();
                s.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
